package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.common.result.PageResult;
import com.quwan.entity.TActivity;
import com.quwan.manager.service.SystemActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
  * @author laozhang
  * @date 2021/11/23 16:01
  */
  @Api(tags = "后台活动管理接口")
  @RestController
  @RequiredArgsConstructor
  @RequestMapping("mgr/activity")
  public class SystemActivityController extends BaseController {
     private final SystemActivityService systemActivityService;

     @ApiOperation("活动管理列表——分页")
     @PostMapping("activityListPage")
     public ApiResult<PageResult<TActivity>> activityListPage(@RequestParam(defaultValue = "1") int page,
                                                                 @RequestParam(defaultValue = "10") int size,
                                                                 @ApiParam("ID") @RequestParam(required = false) Integer id,
                                                                 @ApiParam("标题") @RequestParam(required = false) String title) {
         PageResult<TActivity> res = systemActivityService.getActivityListPage(page,size,id,title);
         return ApiResult.success(res);
     }

     @ApiOperation("活动管理列表")
     @PostMapping("activityList")
     public ApiResult<List<TActivity>> activityList(@ApiParam("ID") @RequestParam(required = false) Integer id,
             @ApiParam("标题") @RequestParam(required = false) String title) {
         List<TActivity> res = systemActivityService.getActivityList(id,title);
         return ApiResult.success(res);
     }

    @ApiOperation("活动管理——详情")
    @PostMapping("detailAactivity")
    public ApiResult detailAactivity(@ApiParam("id") @RequestParam(required = true) Integer id) {
        TActivity activity = systemActivityService.detailActivity(id);
        return ApiResult.success(activity);
    }

    @ApiOperation("活动管理——增加")
    @PostMapping("addAactivity")
    public ApiResult addAactivity(TActivity tActivity) {
        boolean success = systemActivityService.addActivity(tActivity);
        if (success) return ApiResult.success();
        else return ApiResult.failed();
    }

    @ApiOperation("活动管理——修改")
    @PostMapping("updateAactivity")
    public ApiResult updateAactivity(TActivity tActivity) {
        boolean success = systemActivityService.updateActivity(tActivity);
        if (success) return ApiResult.success();
        else return ApiResult.failed();
    }

    @ApiOperation("活动管理——删除")
    @PostMapping("delAactivity")
    public ApiResult delAactivity(@ApiParam("id") @RequestParam(required = true) Integer id) {
        boolean success = systemActivityService.delActivity(id);
        if (success) return ApiResult.success();
        else return ApiResult.failed();
    }

}
